package structual_pattern.composite_pattern;

import java.lang.reflect.Array;
import java.util.ArrayList;

public class CompositePattern {

}
abstract class Component{
    public abstract void add(Component component);
    public abstract void remove(Component component);
    public abstract Component getComponent(int i);
    public abstract void operate();

}
class Leaf extends Component{
    @Override
    public void add(Component component) {
        //null
    }

    @Override
    public void remove(Component component) {
//null
    }

    @Override
    public Component getComponent(int i) {
        return null;
    }

    @Override
    public void operate() {
        System.out.println("leaf");
    }
}
class Composite extends Component{
    private ArrayList<Component> list = new ArrayList<>();
    @Override
    public void add(Component component) {
        list.add(component);
    }

    @Override
    public void remove(Component component) {
        list.remove(component);
    }

    @Override
    public Component getComponent(int i) {
        return list.get(i);
    }

    @Override
    public void operate() {
        for (Component component : list) {
            component.operate();
        }
    }
}